package com.demo.mystudy.ui.socketserver.servercmd

import com.demo.mystudy.socketbean.JetinnoFolderBean
import com.demo.mystudy.socketbean.MessageWrapper
import com.jetinno.simple.utils.FilePath
import com.jetinno.simple.utils.FileUtil
import com.jetinno.simple.utils.JsonUtil
import org.java_websocket.WebSocket
import java.io.File

/**
 * Created by zhangyuncai on 2025/4/28.
 * 描述：
 */
object ServerCmdJetinnoFolder : ServerCmdInterface {
    override val cmd: String
        get() = "JetinnoFolder"

    override fun receive(conn: WebSocket, messageWrapper: MessageWrapper) {
        var bean = JsonUtil.jsonToAny(messageWrapper.message, JetinnoFolderBean::class.java)
        if (bean == null) {
            bean = JetinnoFolderBean()
            bean.parentPath = "Jetinno"
            bean.cmd = cmd
        }
        val file = File(FilePath.EXTERNAL_STORAGE_FILE, bean.parentPath)//获取父文件夹
        val childFileList = FileUtil.getOneFilesPath(file)//获取该文件夹下所有文件路径

        bean.childPathList = childFileList
        conn.send(JsonUtil.anyToJson(bean))
    }
}
